#include "snmpinc.h"
#include "mib2_system_mib.h"
void set_hostname(char *hname);

_INT16 mib2_SystemScalar_Handler(_UINT8 request,VB_T *vbp)
{
	_UINT8 *tmp;
	_UINT32 valOid[]= {1,3,6,1,4,1,42936,1};
	switch(*(vbp->pLeafId))
	{
	default:
		return GEN_ERR;
		/* ================================================================= */
	case LEAF_sysDescr: /*oid 1 , TYPE_OCTET_STRING(2),read-only*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			octetSet(vbp,(_UINT8 *)gSysDescr,strlen(gSysDescr));
			break;
		case SET_REQUEST_PDU:
			return NOT_WRITABLE;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysObjectID: /*oid 2 , TYPE_OBJECT_IDENTIFIER(3),read-only*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			oidSet(vbp,valOid,sizeof(valOid)/sizeof(_UINT32));
			break;
		case SET_REQUEST_PDU:
			return NOT_WRITABLE;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysUpTime: /*oid 3 , TYPE_TimeTicks(4),read-only*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			TimetickSet(vbp,get_sysuptime()*100);
			break;
		case SET_REQUEST_PDU:
			return NOT_WRITABLE;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysContact: /*oid 4 , TYPE_OCTET_STRING(2),read-write*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			octetSet(vbp,(_UINT8 *)gSysContact,strlen((char *)gSysContact));
			break;
		case SET_REQUEST_PDU:
			if(vbp->vb_data_length>=SYSNAME_LEN)
			{
				vbp->vb_data_length=SYSNAME_LEN-1;
			}
			tmp=(_UINT8 *)octetGet(vbp);
			tmp[vbp->vb_data_length]=0;
			strcpy(gSysContact,(char *)tmp);
			break;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysName: /*oid 5 , TYPE_OCTET_STRING(2),read-write*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			octetSet(vbp,(_UINT8 *)gSysName,strlen(gSysName));
			break;
		case SET_REQUEST_PDU:
			if(vbp->vb_data_length>=SYSNAME_LEN)
			{
				vbp->vb_data_length=SYSNAME_LEN-1;
			}
			tmp=(_UINT8 *)octetGet(vbp);
			tmp[vbp->vb_data_length]=0;
			strcpy(gSysName,(char *)tmp);
			//set_hostname((char *)tmp);
			break;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysLocation: /*oid 6 , TYPE_OCTET_STRING(2),read-write*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			octetSet(vbp,(_UINT8 *)gSysLocation,strlen(gSysLocation));
			break;
		case SET_REQUEST_PDU:
			if(vbp->vb_data_length>=SYSNAME_LEN)
			{
				vbp->vb_data_length=SYSNAME_LEN-1;
			}
			tmp=(_UINT8 *)octetGet(vbp);
			tmp[vbp->vb_data_length]=0;
			strcpy(gSysLocation,(char *)tmp);
			break;
		}
		break;
	}
	/* ================================================================= */
	case LEAF_sysServices: /*oid 7 , TYPE_INTEGER(1),read-only*/
	{
		switch(request)
		{
		case GET_NEXT_REQUEST_PDU:
		case GET_REQUEST_PDU:
			Int32Set(vbp,69);
			break;
		case SET_REQUEST_PDU:
			return NOT_WRITABLE;
		}
		break;
	}
	}
	return NO_ERROR;
}

